package cn.tedu.spring.eg4;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class ShopController {
    private String username;

    // 1.调用无参构造方法进行bean对象创建
    private ShopController(){
        System.out.println("1.bean对象,调有无参方法");
    }
    public ShopController(String username) {
        this.username = username;
    }

    public String getUsername() {
        return username;
    }
    /**
     * 2.通过set()方法进行属性赋值
     */
    @Value("蔡徐坤")
    public void setUsername(String username) {
        this.username = username;
        System.out.println("2.给对象赋值");
    }
    @PostConstruct
    private void init(){
        System.out.println("3.初始化阶段");
    }
    @PreDestroy
    private void destroy(){
        System.out.println("5.销毁阶段,释放资源");
    }

    @Override
    public String toString() {
        return "ShopController{" +
                "username='" + username + '\'' +
                '}';
    }
}
